#coding=utf-8
import json
from python3.common.core.handler.base_handler import BaseHandler
import re
import urllib2
import os
import sys
import xlwt
import xlrd
import time
import conf
from python3.common.util.util import getUuid
reload(sys)
sys.setdefaultencoding("utf-8")

class Control362(BaseHandler):
    def get(self):
        kw=self.get_argument("kw","")
        url="http://open.api.tianyancha.com/services/v4/open/baseinfo"
        #print(kw)
        return_json={}

        # print kw
        # return return_json
        if kw=="":
            return_json["error_code"]="300000";
            return_json["reason"]="找不到id或者name"
        else:
            numpat=re.compile(u'\d+')
            num_result=numpat.findall(kw)

            if len(num_result)>0 and  num_result[0]==kw:#代表是id
                #print("发送搜索id的请求")
                url+="?id="+kw
                req = urllib2.Request(url)
                req.add_header("Authorization", conf.Authorization)
                res_data = urllib2.urlopen(req)
                res = res_data.read()
                return_json=json.loads(str(res))
                #json.loads('''{"error_code":0,"reason":"ok","result":{"updatetime":1530084562162,"fromTime":991670400000,"type":1,"categoryScore":9436,"id":22822,"regNumber":"110108002734659","percentileScore":9723,"regCapital":"642128.000000万人民币","regInstitute":"北京市工商行政管理局海淀分局","name":"北京百度网讯科技有限公司","regLocation":"北京市海淀区上地十街10号百度大厦2层","industry":"科技推广和应用服务业","approvedTime":1529856000000,"logo":"http://img.tianyancha.com/logo/lll/36089e162a250252363a05d74b96185b.png@!watermark01","orgApprovedInstitute":"北京市质量技术监督局","taxNumber":"91110000802100433B","businessScope":"技术服务、技术培训、技术推广；设计、开发、销售计算机软件；经济信息咨询；利用www.baidu.com、www.hao123.com(www.hao222.net、www.hao222.com)网站发布广告；设计、制作、代理、发布广告；货物进出口、技术进出口、代理进出口；医疗软件技术开发；委托生产电子产品、玩具、照相器材；销售家用电器、机械设备、五金交电、电子产品、文化用品、照相器材、计算机、软件及辅助设备、化妆品、卫生用品、体育用品、纺织品、服装、鞋帽、日用品、家具、首饰、避孕器具、工艺品、钟表、眼镜、玩具、汽车及摩托车配件、仪器仪表、塑料制品、花、草及观赏植物、建筑材料、通讯设备；预防保健咨询；公园门票、文艺演出、体育赛事、展览会票务代理；翻译服务；因特网信息服务业务（除出版、教育、医疗保健以外的内容）；第一类增值电信业务中的在线数据处理与交易处理业务、国内因特网虚拟专用网业务、因特网数据中心业务；第二类增值电信业务中的因特网接入服务业务、呼叫中心业务、信息服务业务（不含固定网电话信息服务和互联网信息服务）；图书、电子出版物、音像制品批发、零售、网上销售；利用信息网络经营音乐娱乐产品，游戏产品，演出剧（节）目、表演，动漫产品（文化经营许可证有效期至2020年04月17日）；演出经纪；人才中介服务。（企业依法自主选择经营项目，开展经营活动；演出经纪、人才中介服务以及依法须经批准的项目，经相关部门批准后依批准的内容开展经营活动；不得从事本市产业政策禁止和限制类项目的经营活动。）","property4":"110108802100433","property3":"Beijing Baidu Netcom Science and Technology Co.,Ltd.","orgNumber":"802100433","regStatus":"开业","estiblishTime":991670400000,"legalPersonName":"梁志祥","toTime":1622736000000,"legalPersonId":2020172991,"sourceFlag":"http://qyxy.baic.gov.cn/","actualCapital":"","flag":1,"correctCompanyId":"","companyOrgType":"有限责任公司(自然人投资或控股)","base":"bj","updateTimes":1530084554000,"companyType":32767,"creditCode":"91110000802100433B","companyId":431}}''')
            else:#
                #print("发送搜索name的请求")
                url += "?name=" + kw
                req = urllib2.Request(url)
                req.add_header("Authorization", conf.Authorization)
                res_data = urllib2.urlopen(req)
                res = res_data.read()
                return_json = json.loads(str(res))
                #return_json = json.loads(
                 #   '''{"error_code":0,"reason":"ok","result":{"updatetime":1530084562162,"fromTime":991670400000,"type":1,"categoryScore":9436,"id":22822,"regNumber":"110108002734659","percentileScore":9723,"regCapital":"642128.000000万人民币","regInstitute":"北京市工商行政管理局海淀分局","name":"北京百度网讯科技有限公司","regLocation":"北京市海淀区上地十街10号百度大厦2层","industry":"科技推广和应用服务业","approvedTime":1529856000000,"logo":"http://img.tianyancha.com/logo/lll/36089e162a250252363a05d74b96185b.png@!watermark01","orgApprovedInstitute":"北京市质量技术监督局","taxNumber":"91110000802100433B","businessScope":"技术服务、技术培训、技术推广；设计、开发、销售计算机软件；经济信息咨询；利用www.baidu.com、www.hao123.com(www.hao222.net、www.hao222.com)网站发布广告；设计、制作、代理、发布广告；货物进出口、技术进出口、代理进出口；医疗软件技术开发；委托生产电子产品、玩具、照相器材；销售家用电器、机械设备、五金交电、电子产品、文化用品、照相器材、计算机、软件及辅助设备、化妆品、卫生用品、体育用品、纺织品、服装、鞋帽、日用品、家具、首饰、避孕器具、工艺品、钟表、眼镜、玩具、汽车及摩托车配件、仪器仪表、塑料制品、花、草及观赏植物、建筑材料、通讯设备；预防保健咨询；公园门票、文艺演出、体育赛事、展览会票务代理；翻译服务；因特网信息服务业务（除出版、教育、医疗保健以外的内容）；第一类增值电信业务中的在线数据处理与交易处理业务、国内因特网虚拟专用网业务、因特网数据中心业务；第二类增值电信业务中的因特网接入服务业务、呼叫中心业务、信息服务业务（不含固定网电话信息服务和互联网信息服务）；图书、电子出版物、音像制品批发、零售、网上销售；利用信息网络经营音乐娱乐产品，游戏产品，演出剧（节）目、表演，动漫产品（文化经营许可证有效期至2020年04月17日）；演出经纪；人才中介服务。（企业依法自主选择经营项目，开展经营活动；演出经纪、人才中介服务以及依法须经批准的项目，经相关部门批准后依批准的内容开展经营活动；不得从事本市产业政策禁止和限制类项目的经营活动。）","property4":"110108802100433","property3":"Beijing Baidu Netcom Science and Technology Co.,Ltd.","orgNumber":"802100433","regStatus":"开业","estiblishTime":991670400000,"legalPersonName":"梁志祥","toTime":1622736000000,"legalPersonId":2020172991,"sourceFlag":"http://qyxy.baic.gov.cn/","actualCapital":"","flag":1,"correctCompanyId":"","companyOrgType":"有限责任公司(自然人投资或控股)","base":"bj","updateTimes":1530084554000,"companyType":32767,"creditCode":"91110000802100433B","companyId":431}}''')
        self.write(return_json)


class Control364(BaseHandler):
    def get(self):
        kw=self.get_argument("kw","")
        url="http://open.api.tianyancha.com/services/v4/open/baseinfoV2"
        #print(kw)
        return_json={}

        # print kw
        # return return_json
        if kw=="":
            return_json["error_code"]="300000";
            return_json["reason"]="找不到id或者name"
        else:
            numpat=re.compile(u'\d+')
            num_result=numpat.findall(kw)

            if len(num_result)>0 and  num_result[0]==kw:#代表是id
                #print("发送搜索id的请求")
                url+="?id="+kw
                req = urllib2.Request(url)
                req.add_header("Authorization", conf.Authorization)
                res_data = urllib2.urlopen(req)
                res = res_data.read()
                return_json=json.loads(str(res))
                #json.loads('''{"error_code":0,"reason":"ok","result":{"updatetime":1530084562162,"fromTime":991670400000,"type":1,"categoryScore":9436,"id":22822,"regNumber":"110108002734659","percentileScore":9723,"regCapital":"642128.000000万人民币","regInstitute":"北京市工商行政管理局海淀分局","name":"北京百度网讯科技有限公司","regLocation":"北京市海淀区上地十街10号百度大厦2层","industry":"科技推广和应用服务业","approvedTime":1529856000000,"logo":"http://img.tianyancha.com/logo/lll/36089e162a250252363a05d74b96185b.png@!watermark01","orgApprovedInstitute":"北京市质量技术监督局","taxNumber":"91110000802100433B","businessScope":"技术服务、技术培训、技术推广；设计、开发、销售计算机软件；经济信息咨询；利用www.baidu.com、www.hao123.com(www.hao222.net、www.hao222.com)网站发布广告；设计、制作、代理、发布广告；货物进出口、技术进出口、代理进出口；医疗软件技术开发；委托生产电子产品、玩具、照相器材；销售家用电器、机械设备、五金交电、电子产品、文化用品、照相器材、计算机、软件及辅助设备、化妆品、卫生用品、体育用品、纺织品、服装、鞋帽、日用品、家具、首饰、避孕器具、工艺品、钟表、眼镜、玩具、汽车及摩托车配件、仪器仪表、塑料制品、花、草及观赏植物、建筑材料、通讯设备；预防保健咨询；公园门票、文艺演出、体育赛事、展览会票务代理；翻译服务；因特网信息服务业务（除出版、教育、医疗保健以外的内容）；第一类增值电信业务中的在线数据处理与交易处理业务、国内因特网虚拟专用网业务、因特网数据中心业务；第二类增值电信业务中的因特网接入服务业务、呼叫中心业务、信息服务业务（不含固定网电话信息服务和互联网信息服务）；图书、电子出版物、音像制品批发、零售、网上销售；利用信息网络经营音乐娱乐产品，游戏产品，演出剧（节）目、表演，动漫产品（文化经营许可证有效期至2020年04月17日）；演出经纪；人才中介服务。（企业依法自主选择经营项目，开展经营活动；演出经纪、人才中介服务以及依法须经批准的项目，经相关部门批准后依批准的内容开展经营活动；不得从事本市产业政策禁止和限制类项目的经营活动。）","property4":"110108802100433","property3":"Beijing Baidu Netcom Science and Technology Co.,Ltd.","orgNumber":"802100433","regStatus":"开业","estiblishTime":991670400000,"legalPersonName":"梁志祥","toTime":1622736000000,"legalPersonId":2020172991,"sourceFlag":"http://qyxy.baic.gov.cn/","actualCapital":"","flag":1,"correctCompanyId":"","companyOrgType":"有限责任公司(自然人投资或控股)","base":"bj","updateTimes":1530084554000,"companyType":32767,"creditCode":"91110000802100433B","companyId":431}}''')
            else:#
                #print("发送搜索name的请求")
                url += "?name=" + kw
                req = urllib2.Request(url)
                req.add_header("Authorization", conf.Authorization)
                res_data = urllib2.urlopen(req)
                res = res_data.read()
                return_json = json.loads(str(res))
                #return_json = json.loads(
                 #   '''{"error_code":0,"reason":"ok","result":{"updatetime":1530084562162,"fromTime":991670400000,"type":1,"categoryScore":9436,"id":22822,"regNumber":"110108002734659","percentileScore":9723,"regCapital":"642128.000000万人民币","regInstitute":"北京市工商行政管理局海淀分局","name":"北京百度网讯科技有限公司","regLocation":"北京市海淀区上地十街10号百度大厦2层","industry":"科技推广和应用服务业","approvedTime":1529856000000,"logo":"http://img.tianyancha.com/logo/lll/36089e162a250252363a05d74b96185b.png@!watermark01","orgApprovedInstitute":"北京市质量技术监督局","taxNumber":"91110000802100433B","businessScope":"技术服务、技术培训、技术推广；设计、开发、销售计算机软件；经济信息咨询；利用www.baidu.com、www.hao123.com(www.hao222.net、www.hao222.com)网站发布广告；设计、制作、代理、发布广告；货物进出口、技术进出口、代理进出口；医疗软件技术开发；委托生产电子产品、玩具、照相器材；销售家用电器、机械设备、五金交电、电子产品、文化用品、照相器材、计算机、软件及辅助设备、化妆品、卫生用品、体育用品、纺织品、服装、鞋帽、日用品、家具、首饰、避孕器具、工艺品、钟表、眼镜、玩具、汽车及摩托车配件、仪器仪表、塑料制品、花、草及观赏植物、建筑材料、通讯设备；预防保健咨询；公园门票、文艺演出、体育赛事、展览会票务代理；翻译服务；因特网信息服务业务（除出版、教育、医疗保健以外的内容）；第一类增值电信业务中的在线数据处理与交易处理业务、国内因特网虚拟专用网业务、因特网数据中心业务；第二类增值电信业务中的因特网接入服务业务、呼叫中心业务、信息服务业务（不含固定网电话信息服务和互联网信息服务）；图书、电子出版物、音像制品批发、零售、网上销售；利用信息网络经营音乐娱乐产品，游戏产品，演出剧（节）目、表演，动漫产品（文化经营许可证有效期至2020年04月17日）；演出经纪；人才中介服务。（企业依法自主选择经营项目，开展经营活动；演出经纪、人才中介服务以及依法须经批准的项目，经相关部门批准后依批准的内容开展经营活动；不得从事本市产业政策禁止和限制类项目的经营活动。）","property4":"110108802100433","property3":"Beijing Baidu Netcom Science and Technology Co.,Ltd.","orgNumber":"802100433","regStatus":"开业","estiblishTime":991670400000,"legalPersonName":"梁志祥","toTime":1622736000000,"legalPersonId":2020172991,"sourceFlag":"http://qyxy.baic.gov.cn/","actualCapital":"","flag":1,"correctCompanyId":"","companyOrgType":"有限责任公司(自然人投资或控股)","base":"bj","updateTimes":1530084554000,"companyType":32767,"creditCode":"91110000802100433B","companyId":431}}''')
        self.write(return_json)
        #     return_json=json.loads('''{"error_code":0,"reason":"ok","result":{"updatetime":1530084562162,"fromTime":991670400000,"type":1,"categoryScore":9436,"id":22822,"regNumber":"110108002734659","percentileScore":9723,"phoneNumber":"010-59928888","regCapital":"642128.000000万人民币","regInstitute":"北京市工商行政管理局海淀分局","name":"北京百度网讯科技有限公司","regLocation":"北京市海淀区上地十街10号百度大厦2层","industry":"科技推广和应用服务业","approvedTime":1529856000000,"logo":"http://img.tianyancha.com/logo/lll/36089e162a250252363a05d74b96185b.png@!watermark01","orgApprovedInstitute":"北京市质量技术监督局","taxNumber":"91110000802100433B","businessScope":"技术服务、技术培训、技术推广；设计、开发、销售计算机软件；经济信息咨询；利用www.baidu.com、www.hao123.com(www.hao222.net、www.hao222.com)网站发布广告；设计、制作、代理、发布广告；货物进出口、技术进出口、代理进出口；医疗软件技术开发；委托生产电子产品、玩具、照相器材；销售家用电器、机械设备、五金交电、电子产品、文化用品、照相器材、计算机、软件及辅助设备、化妆品、卫生用品、体育用品、纺织品、服装、鞋帽、日用品、家具、首饰、避孕器具、工艺品、钟表、眼镜、玩具、汽车及摩托车配件、仪器仪表、塑料制品、花、草及观赏植物、建筑材料、通讯设备；预防保健咨询；公园门票、文艺演出、体育赛事、展览会票务代理；翻译服务；因特网信息服务业务（除出版、教育、医疗保健以外的内容）；第一类增值电信业务中的在线数据处理与交易处理业务、国内因特网虚拟专用网业务、因特网数据中心业务；第二类增值电信业务中的因特网接入服务业务、呼叫中心业务、信息服务业务（不含固定网电话信息服务和互联网信息服务）；图书、电子出版物、音像制品批发、零售、网上销售；利用信息网络经营音乐娱乐产品，游戏产品，演出剧（节）目、表演，动漫产品（文化经营许可证有效期至2020年04月17日）；演出经纪；人才中介服务。（企业依法自主选择经营项目，开展经营活动；演出经纪、人才中介服务以及依法须经批准的项目，经相关部门批准后依批准的内容开展经营活动；不得从事本市产业政策禁止和限制类项目的经营活动。）","property4":"110108802100433","property3":"Beijing Baidu Netcom Science and Technology Co.,Ltd.","orgNumber":"802100433","regStatus":"开业","estiblishTime":991670400000,"legalPersonName":"梁志祥","toTime":1622736000000,"legalPersonId":2020172991,"sourceFlag":"http://qyxy.baic.gov.cn/","actualCapital":"","websiteList":"www.baidu.com","flag":1,"correctCompanyId":"","companyOrgType":"有限责任公司(自然人投资或控股)","base":"bj","updateTimes":1530084554000,"companyType":32767,"creditCode":"91110000802100433B","companyId":431}}''')
        # self.write(return_json)


class Control365(BaseHandler):
    def get(self):
        kw=self.get_argument("kw","")
        url="http://open.api.tianyancha.com/services/v4/open/baseinfoV3"
        #print(kw)
        return_json={}

        # print kw
        # return return_json
        if kw=="":
            return_json["error_code"]="300000";
            return_json["reason"]="找不到id或者name"
        else:
            numpat=re.compile(u'\d+')
            num_result=numpat.findall(kw)

            if len(num_result)>0 and  num_result[0]==kw:#代表是id
                #print("发送搜索id的请求")
                url+="?id="+kw
                req = urllib2.Request(url)
                req.add_header("Authorization", conf.Authorization)
                res_data = urllib2.urlopen(req)
                res = res_data.read()
                return_json=json.loads(str(res))
                #json.loads('''{"error_code":0,"reason":"ok","result":{"updatetime":1530084562162,"fromTime":991670400000,"type":1,"categoryScore":9436,"id":22822,"regNumber":"110108002734659","percentileScore":9723,"regCapital":"642128.000000万人民币","regInstitute":"北京市工商行政管理局海淀分局","name":"北京百度网讯科技有限公司","regLocation":"北京市海淀区上地十街10号百度大厦2层","industry":"科技推广和应用服务业","approvedTime":1529856000000,"logo":"http://img.tianyancha.com/logo/lll/36089e162a250252363a05d74b96185b.png@!watermark01","orgApprovedInstitute":"北京市质量技术监督局","taxNumber":"91110000802100433B","businessScope":"技术服务、技术培训、技术推广；设计、开发、销售计算机软件；经济信息咨询；利用www.baidu.com、www.hao123.com(www.hao222.net、www.hao222.com)网站发布广告；设计、制作、代理、发布广告；货物进出口、技术进出口、代理进出口；医疗软件技术开发；委托生产电子产品、玩具、照相器材；销售家用电器、机械设备、五金交电、电子产品、文化用品、照相器材、计算机、软件及辅助设备、化妆品、卫生用品、体育用品、纺织品、服装、鞋帽、日用品、家具、首饰、避孕器具、工艺品、钟表、眼镜、玩具、汽车及摩托车配件、仪器仪表、塑料制品、花、草及观赏植物、建筑材料、通讯设备；预防保健咨询；公园门票、文艺演出、体育赛事、展览会票务代理；翻译服务；因特网信息服务业务（除出版、教育、医疗保健以外的内容）；第一类增值电信业务中的在线数据处理与交易处理业务、国内因特网虚拟专用网业务、因特网数据中心业务；第二类增值电信业务中的因特网接入服务业务、呼叫中心业务、信息服务业务（不含固定网电话信息服务和互联网信息服务）；图书、电子出版物、音像制品批发、零售、网上销售；利用信息网络经营音乐娱乐产品，游戏产品，演出剧（节）目、表演，动漫产品（文化经营许可证有效期至2020年04月17日）；演出经纪；人才中介服务。（企业依法自主选择经营项目，开展经营活动；演出经纪、人才中介服务以及依法须经批准的项目，经相关部门批准后依批准的内容开展经营活动；不得从事本市产业政策禁止和限制类项目的经营活动。）","property4":"110108802100433","property3":"Beijing Baidu Netcom Science and Technology Co.,Ltd.","orgNumber":"802100433","regStatus":"开业","estiblishTime":991670400000,"legalPersonName":"梁志祥","toTime":1622736000000,"legalPersonId":2020172991,"sourceFlag":"http://qyxy.baic.gov.cn/","actualCapital":"","flag":1,"correctCompanyId":"","companyOrgType":"有限责任公司(自然人投资或控股)","base":"bj","updateTimes":1530084554000,"companyType":32767,"creditCode":"91110000802100433B","companyId":431}}''')
            else:#
                #print("发送搜索name的请求")
                url += "?name=" + kw
                req = urllib2.Request(url)
                req.add_header("Authorization", conf.Authorization)
                res_data = urllib2.urlopen(req)
                res = res_data.read()
                return_json = json.loads(str(res))
                #return_json = json.loads(
                 #   '''{"error_code":0,"reason":"ok","result":{"updatetime":1530084562162,"fromTime":991670400000,"type":1,"categoryScore":9436,"id":22822,"regNumber":"110108002734659","percentileScore":9723,"regCapital":"642128.000000万人民币","regInstitute":"北京市工商行政管理局海淀分局","name":"北京百度网讯科技有限公司","regLocation":"北京市海淀区上地十街10号百度大厦2层","industry":"科技推广和应用服务业","approvedTime":1529856000000,"logo":"http://img.tianyancha.com/logo/lll/36089e162a250252363a05d74b96185b.png@!watermark01","orgApprovedInstitute":"北京市质量技术监督局","taxNumber":"91110000802100433B","businessScope":"技术服务、技术培训、技术推广；设计、开发、销售计算机软件；经济信息咨询；利用www.baidu.com、www.hao123.com(www.hao222.net、www.hao222.com)网站发布广告；设计、制作、代理、发布广告；货物进出口、技术进出口、代理进出口；医疗软件技术开发；委托生产电子产品、玩具、照相器材；销售家用电器、机械设备、五金交电、电子产品、文化用品、照相器材、计算机、软件及辅助设备、化妆品、卫生用品、体育用品、纺织品、服装、鞋帽、日用品、家具、首饰、避孕器具、工艺品、钟表、眼镜、玩具、汽车及摩托车配件、仪器仪表、塑料制品、花、草及观赏植物、建筑材料、通讯设备；预防保健咨询；公园门票、文艺演出、体育赛事、展览会票务代理；翻译服务；因特网信息服务业务（除出版、教育、医疗保健以外的内容）；第一类增值电信业务中的在线数据处理与交易处理业务、国内因特网虚拟专用网业务、因特网数据中心业务；第二类增值电信业务中的因特网接入服务业务、呼叫中心业务、信息服务业务（不含固定网电话信息服务和互联网信息服务）；图书、电子出版物、音像制品批发、零售、网上销售；利用信息网络经营音乐娱乐产品，游戏产品，演出剧（节）目、表演，动漫产品（文化经营许可证有效期至2020年04月17日）；演出经纪；人才中介服务。（企业依法自主选择经营项目，开展经营活动；演出经纪、人才中介服务以及依法须经批准的项目，经相关部门批准后依批准的内容开展经营活动；不得从事本市产业政策禁止和限制类项目的经营活动。）","property4":"110108802100433","property3":"Beijing Baidu Netcom Science and Technology Co.,Ltd.","orgNumber":"802100433","regStatus":"开业","estiblishTime":991670400000,"legalPersonName":"梁志祥","toTime":1622736000000,"legalPersonId":2020172991,"sourceFlag":"http://qyxy.baic.gov.cn/","actualCapital":"","flag":1,"correctCompanyId":"","companyOrgType":"有限责任公司(自然人投资或控股)","base":"bj","updateTimes":1530084554000,"companyType":32767,"creditCode":"91110000802100433B","companyId":431}}''')
        self.write(return_json)
        #     return_json=json.loads('''{"error_code":0,"reason":"ok","result":{"updatetime":1530084562162,"fromTime":991670400000,"type":1,"categoryScore":9436,"id":22822,"regNumber":"110108002734659","percentileScore":9723,"phoneNumber":"010-59928888","regCapital":"642128.000000万人民币","regInstitute":"北京市工商行政管理局海淀分局","name":"北京百度网讯科技有限公司","regLocation":"北京市海淀区上地十街10号百度大厦2层","staffList":{"total":3,"result":[{"id":2020172991,"toco":25,"logo":"http://img.tianyancha.com/logo/human2/bdb7e91f798d66661ade0c4bbb3d54bf.png@!watermark01","name":"梁志祥","typeJoin":["经理"],"type":2},{"id":1984012283,"toco":13,"logo":"http://img.tianyancha.com/logo/human/2/345609db75383b411884a401a6f3665e.png@!watermark01","name":"李彦宏","typeJoin":["执行董事"],"type":2},{"id":1839080315,"toco":37,"logo":"http://img.tianyancha.com/logo/human2/bdfe53ae98a2256d988da372ba8d879c.png@!watermark01","name":"向海龙","typeJoin":["监事"],"type":2}]},"industry":"科技推广和应用服务业","approvedTime":1529856000000,"logo":"http://img.tianyancha.com/logo/lll/36089e162a250252363a05d74b96185b.png@!watermark01","orgApprovedInstitute":"北京市质量技术监督局","taxNumber":"91110000802100433B","businessScope":"技术服务、技术培训、技术推广；设计、开发、销售计算机软件；经济信息咨询；利用www.baidu.com、www.hao123.com(www.hao222.net、www.hao222.com)网站发布广告；设计、制作、代理、发布广告；货物进出口、技术进出口、代理进出口；医疗软件技术开发；委托生产电子产品、玩具、照相器材；销售家用电器、机械设备、五金交电、电子产品、文化用品、照相器材、计算机、软件及辅助设备、化妆品、卫生用品、体育用品、纺织品、服装、鞋帽、日用品、家具、首饰、避孕器具、工艺品、钟表、眼镜、玩具、汽车及摩托车配件、仪器仪表、塑料制品、花、草及观赏植物、建筑材料、通讯设备；预防保健咨询；公园门票、文艺演出、体育赛事、展览会票务代理；翻译服务；因特网信息服务业务（除出版、教育、医疗保健以外的内容）；第一类增值电信业务中的在线数据处理与交易处理业务、国内因特网虚拟专用网业务、因特网数据中心业务；第二类增值电信业务中的因特网接入服务业务、呼叫中心业务、信息服务业务（不含固定网电话信息服务和互联网信息服务）；图书、电子出版物、音像制品批发、零售、网上销售；利用信息网络经营音乐娱乐产品，游戏产品，演出剧（节）目、表演，动漫产品（文化经营许可证有效期至2020年04月17日）；演出经纪；人才中介服务。（企业依法自主选择经营项目，开展经营活动；演出经纪、人才中介服务以及依法须经批准的项目，经相关部门批准后依批准的内容开展经营活动；不得从事本市产业政策禁止和限制类项目的经营活动。）","property4":"110108802100433","property3":"Beijing Baidu Netcom Science and Technology Co.,Ltd.","orgNumber":"802100433","regStatus":"开业","estiblishTime":991670400000,"legalPersonName":"梁志祥","toTime":1622736000000,"legalPersonId":2020172991,"sourceFlag":"http://qyxy.baic.gov.cn/","actualCapital":"","websiteList":"www.baidu.com","flag":1,"correctCompanyId":"","companyOrgType":"有限责任公司(自然人投资或控股)","base":"bj","updateTimes":1530084554000,"companyType":32767,"creditCode":"91110000802100433B","companyId":431}}''')
        # self.write(return_json)

class Control736(BaseHandler):
    def get(self):
        kw=self.get_argument("kw","")
        url="http://open.api.tianyancha.com/services/v4/open/getCompanyByCode"
        #print(kw)
        return_json={}

        # print kw
        # return return_json
        if kw=="":
            return_json["error_code"]="300000";
            return_json["reason"]="code"
        else:

            #print("发送搜索name的请求")
            url += "?code=" + kw
            req = urllib2.Request(url)
            req.add_header("Authorization", conf.Authorization)
            res_data = urllib2.urlopen(req)
            res = res_data.read()
            return_json = json.loads(str(res))
                #return_json = json.loads(
                 #   '''{"error_code":0,"reason":"ok","result":{"updatetime":1530084562162,"fromTime":991670400000,"type":1,"categoryScore":9436,"id":22822,"regNumber":"110108002734659","percentileScore":9723,"regCapital":"642128.000000万人民币","regInstitute":"北京市工商行政管理局海淀分局","name":"北京百度网讯科技有限公司","regLocation":"北京市海淀区上地十街10号百度大厦2层","industry":"科技推广和应用服务业","approvedTime":1529856000000,"logo":"http://img.tianyancha.com/logo/lll/36089e162a250252363a05d74b96185b.png@!watermark01","orgApprovedInstitute":"北京市质量技术监督局","taxNumber":"91110000802100433B","businessScope":"技术服务、技术培训、技术推广；设计、开发、销售计算机软件；经济信息咨询；利用www.baidu.com、www.hao123.com(www.hao222.net、www.hao222.com)网站发布广告；设计、制作、代理、发布广告；货物进出口、技术进出口、代理进出口；医疗软件技术开发；委托生产电子产品、玩具、照相器材；销售家用电器、机械设备、五金交电、电子产品、文化用品、照相器材、计算机、软件及辅助设备、化妆品、卫生用品、体育用品、纺织品、服装、鞋帽、日用品、家具、首饰、避孕器具、工艺品、钟表、眼镜、玩具、汽车及摩托车配件、仪器仪表、塑料制品、花、草及观赏植物、建筑材料、通讯设备；预防保健咨询；公园门票、文艺演出、体育赛事、展览会票务代理；翻译服务；因特网信息服务业务（除出版、教育、医疗保健以外的内容）；第一类增值电信业务中的在线数据处理与交易处理业务、国内因特网虚拟专用网业务、因特网数据中心业务；第二类增值电信业务中的因特网接入服务业务、呼叫中心业务、信息服务业务（不含固定网电话信息服务和互联网信息服务）；图书、电子出版物、音像制品批发、零售、网上销售；利用信息网络经营音乐娱乐产品，游戏产品，演出剧（节）目、表演，动漫产品（文化经营许可证有效期至2020年04月17日）；演出经纪；人才中介服务。（企业依法自主选择经营项目，开展经营活动；演出经纪、人才中介服务以及依法须经批准的项目，经相关部门批准后依批准的内容开展经营活动；不得从事本市产业政策禁止和限制类项目的经营活动。）","property4":"110108802100433","property3":"Beijing Baidu Netcom Science and Technology Co.,Ltd.","orgNumber":"802100433","regStatus":"开业","estiblishTime":991670400000,"legalPersonName":"梁志祥","toTime":1622736000000,"legalPersonId":2020172991,"sourceFlag":"http://qyxy.baic.gov.cn/","actualCapital":"","flag":1,"correctCompanyId":"","companyOrgType":"有限责任公司(自然人投资或控股)","base":"bj","updateTimes":1530084554000,"companyType":32767,"creditCode":"91110000802100433B","companyId":431}}''')
        self.write(return_json)
        # return_json=json.loads('''{"error_code":0,"reason":"ok","result":{"updatetime":1530084562162,"fromTime":991670400000,"categoryScore":9436,"type":1,"holderlist":[{"id":1984012283,"amount":638917.36,"toco":13,"capitalActl":[],"logo":"http://img.tianyancha.com/logo/human/2/345609db75383b411884a401a6f3665e.png@!watermark01","type":2,"capital":[{"amomon":"638,917.36万元","time":"2018-12-31","percent":"99.50%","paymet":"货币"}],"name":"李彦宏"},{"id":1839080315,"amount":3210.64,"toco":37,"capitalActl":[],"logo":"http://img.tianyancha.com/logo/human2/bdfe53ae98a2256d988da372ba8d879c.png@!watermark01","type":2,"capital":[{"amomon":"3,210.64万元","time":"2018-12-31","percent":"0.50%","paymet":"货币"}],"name":"向海龙"}],"id":22822,"percentileScore":9723,"regNumber":"110108002734659","regCapital":"642128.000000万人民币","name":"北京百度网讯科技有限公司","regInstitute":"北京市工商行政管理局海淀分局","regLocation":"北京市海淀区上地十街10号百度大厦2层","approvedTime":1529856000000,"industry":"科技推广和应用服务业","tags":null,"orgApprovedInstitute":"北京市质量技术监督局","logo":"http://img.tianyancha.com/logo/lll/36089e162a250252363a05d74b96185b.png@!watermark01","businessScope":"技术服务、技术培训、技术推广；设计、开发、销售计算机软件；经济信息咨询；利用www.baidu.com、www.hao123.com(www.hao222.net、www.hao222.com)网站发布广告；设计、制作、代理、发布广告；货物进出口、技术进出口、代理进出口；医疗软件技术开发；委托生产电子产品、玩具、照相器材；销售家用电器、机械设备、五金交电、电子产品、文化用品、照相器材、计算机、软件及辅助设备、化妆品、卫生用品、体育用品、纺织品、服装、鞋帽、日用品、家具、首饰、避孕器具、工艺品、钟表、眼镜、玩具、汽车及摩托车配件、仪器仪表、塑料制品、花、草及观赏植物、建筑材料、通讯设备；预防保健咨询；公园门票、文艺演出、体育赛事、展览会票务代理；翻译服务；因特网信息服务业务（除出版、教育、医疗保健以外的内容）；第一类增值电信业务中的在线数据处理与交易处理业务、国内因特网虚拟专用网业务、因特网数据中心业务；第二类增值电信业务中的因特网接入服务业务、呼叫中心业务、信息服务业务（不含固定网电话信息服务和互联网信息服务）；图书、电子出版物、音像制品批发、零售、网上销售；利用信息网络经营音乐娱乐产品，游戏产品，演出剧（节）目、表演，动漫产品（文化经营许可证有效期至2020年04月17日）；演出经纪；人才中介服务。（企业依法自主选择经营项目，开展经营活动；演出经纪、人才中介服务以及依法须经批准的项目，经相关部门批准后依批准的内容开展经营活动；不得从事本市产业政策禁止和限制类项目的经营活动。）","taxNumber":"91110000802100433B","property4":"110108802100433","property3":"Beijing Baidu Netcom Science and Technology Co.,Ltd.","orgNumber":"802100433","estiblishTime":991670400000,"regStatus":"开业","legalPersonName":"梁志祥","toTime":1622736000000,"legalPersonId":2020172991,"sourceFlag":"http://qyxy.baic.gov.cn/","actualCapital":"","flag":1,"correctCompanyId":"","companyOrgType":"有限责任公司(自然人投资或控股)","updateTimes":1530084554000,"base":"bj","companyType":32767,"creditCode":"91110000802100433B","companyId":431}}''')
        # self.write(return_json)


class Control459(BaseHandler):
    def get(self):
        kw=self.get_argument("kw","")
        url="http://open.api.tianyancha.com/services/v4/open/xgbaseinfoV2"
        #print(kw)
        return_json={}

        # print kw
        # return return_json
        if kw=="":
            return_json["error_code"]="300000";
            return_json["reason"]="找不到id或者name"
        else:
            numpat=re.compile(u'\d+')
            num_result=numpat.findall(kw)

            if len(num_result)>0 and  num_result[0]==kw:#代表是id
                #print("发送搜索id的请求")
                url+="?id="+kw
                req = urllib2.Request(url)
                req.add_header("Authorization", conf.Authorization)
                res_data = urllib2.urlopen(req)
                res = res_data.read()
                return_json=json.loads(str(res))
                #json.loads('''{"error_code":0,"reason":"ok","result":{"updatetime":1530084562162,"fromTime":991670400000,"type":1,"categoryScore":9436,"id":22822,"regNumber":"110108002734659","percentileScore":9723,"regCapital":"642128.000000万人民币","regInstitute":"北京市工商行政管理局海淀分局","name":"北京百度网讯科技有限公司","regLocation":"北京市海淀区上地十街10号百度大厦2层","industry":"科技推广和应用服务业","approvedTime":1529856000000,"logo":"http://img.tianyancha.com/logo/lll/36089e162a250252363a05d74b96185b.png@!watermark01","orgApprovedInstitute":"北京市质量技术监督局","taxNumber":"91110000802100433B","businessScope":"技术服务、技术培训、技术推广；设计、开发、销售计算机软件；经济信息咨询；利用www.baidu.com、www.hao123.com(www.hao222.net、www.hao222.com)网站发布广告；设计、制作、代理、发布广告；货物进出口、技术进出口、代理进出口；医疗软件技术开发；委托生产电子产品、玩具、照相器材；销售家用电器、机械设备、五金交电、电子产品、文化用品、照相器材、计算机、软件及辅助设备、化妆品、卫生用品、体育用品、纺织品、服装、鞋帽、日用品、家具、首饰、避孕器具、工艺品、钟表、眼镜、玩具、汽车及摩托车配件、仪器仪表、塑料制品、花、草及观赏植物、建筑材料、通讯设备；预防保健咨询；公园门票、文艺演出、体育赛事、展览会票务代理；翻译服务；因特网信息服务业务（除出版、教育、医疗保健以外的内容）；第一类增值电信业务中的在线数据处理与交易处理业务、国内因特网虚拟专用网业务、因特网数据中心业务；第二类增值电信业务中的因特网接入服务业务、呼叫中心业务、信息服务业务（不含固定网电话信息服务和互联网信息服务）；图书、电子出版物、音像制品批发、零售、网上销售；利用信息网络经营音乐娱乐产品，游戏产品，演出剧（节）目、表演，动漫产品（文化经营许可证有效期至2020年04月17日）；演出经纪；人才中介服务。（企业依法自主选择经营项目，开展经营活动；演出经纪、人才中介服务以及依法须经批准的项目，经相关部门批准后依批准的内容开展经营活动；不得从事本市产业政策禁止和限制类项目的经营活动。）","property4":"110108802100433","property3":"Beijing Baidu Netcom Science and Technology Co.,Ltd.","orgNumber":"802100433","regStatus":"开业","estiblishTime":991670400000,"legalPersonName":"梁志祥","toTime":1622736000000,"legalPersonId":2020172991,"sourceFlag":"http://qyxy.baic.gov.cn/","actualCapital":"","flag":1,"correctCompanyId":"","companyOrgType":"有限责任公司(自然人投资或控股)","base":"bj","updateTimes":1530084554000,"companyType":32767,"creditCode":"91110000802100433B","companyId":431}}''')
            else:#
                #print("发送搜索name的请求")
                url += "?name=" + kw
                req = urllib2.Request(url)
                req.add_header("Authorization", conf.Authorization)
                res_data = urllib2.urlopen(req)
                res = res_data.read()
                return_json = json.loads(str(res))
                #return_json = json.loads(
                 #   '''{"error_code":0,"reason":"ok","result":{"updatetime":1530084562162,"fromTime":991670400000,"type":1,"categoryScore":9436,"id":22822,"regNumber":"110108002734659","percentileScore":9723,"regCapital":"642128.000000万人民币","regInstitute":"北京市工商行政管理局海淀分局","name":"北京百度网讯科技有限公司","regLocation":"北京市海淀区上地十街10号百度大厦2层","industry":"科技推广和应用服务业","approvedTime":1529856000000,"logo":"http://img.tianyancha.com/logo/lll/36089e162a250252363a05d74b96185b.png@!watermark01","orgApprovedInstitute":"北京市质量技术监督局","taxNumber":"91110000802100433B","businessScope":"技术服务、技术培训、技术推广；设计、开发、销售计算机软件；经济信息咨询；利用www.baidu.com、www.hao123.com(www.hao222.net、www.hao222.com)网站发布广告；设计、制作、代理、发布广告；货物进出口、技术进出口、代理进出口；医疗软件技术开发；委托生产电子产品、玩具、照相器材；销售家用电器、机械设备、五金交电、电子产品、文化用品、照相器材、计算机、软件及辅助设备、化妆品、卫生用品、体育用品、纺织品、服装、鞋帽、日用品、家具、首饰、避孕器具、工艺品、钟表、眼镜、玩具、汽车及摩托车配件、仪器仪表、塑料制品、花、草及观赏植物、建筑材料、通讯设备；预防保健咨询；公园门票、文艺演出、体育赛事、展览会票务代理；翻译服务；因特网信息服务业务（除出版、教育、医疗保健以外的内容）；第一类增值电信业务中的在线数据处理与交易处理业务、国内因特网虚拟专用网业务、因特网数据中心业务；第二类增值电信业务中的因特网接入服务业务、呼叫中心业务、信息服务业务（不含固定网电话信息服务和互联网信息服务）；图书、电子出版物、音像制品批发、零售、网上销售；利用信息网络经营音乐娱乐产品，游戏产品，演出剧（节）目、表演，动漫产品（文化经营许可证有效期至2020年04月17日）；演出经纪；人才中介服务。（企业依法自主选择经营项目，开展经营活动；演出经纪、人才中介服务以及依法须经批准的项目，经相关部门批准后依批准的内容开展经营活动；不得从事本市产业政策禁止和限制类项目的经营活动。）","property4":"110108802100433","property3":"Beijing Baidu Netcom Science and Technology Co.,Ltd.","orgNumber":"802100433","regStatus":"开业","estiblishTime":991670400000,"legalPersonName":"梁志祥","toTime":1622736000000,"legalPersonId":2020172991,"sourceFlag":"http://qyxy.baic.gov.cn/","actualCapital":"","flag":1,"correctCompanyId":"","companyOrgType":"有限责任公司(自然人投资或控股)","base":"bj","updateTimes":1530084554000,"companyType":32767,"creditCode":"91110000802100433B","companyId":431}}''')
        self.write(return_json)
        #     return_json=json.loads('''{"error_code":0,"reason":"ok","result":{"logo":"http://img.tianyancha.com/logo/lll/70f7ed38dd88a566a437de3aede00af8.png@!watermark01","remarksS":"-","nameEn":"Baidu （Hong Kong） Limited ","companyNum":"1189285","estiblishTime":1196092800000,"regStatus":"仍注册","entityType":2,"mortgageS":"无","id":11364828,"haveReport":false,"companyOrgType":"私人股份有限公司","name":"百度（香港）有限公司","base":"hk","liquidationModeS":"-","importantItemsS":"-","weibo":null}}''')
        # self.write(return_json)


class index(BaseHandler):
    #信息页面= =
    def get(self):
        self.render("sys/zhongde/xinxi.html")

class index2(BaseHandler):
    # 税务页面= =
    def get(self):
        self.render("sys/zhongde/shuiwu.html")

class index3(BaseHandler):
    # 批量信息查询页面= =
    def get(self):
        self.render("sys/zhongde/piliangxinxi.html")


class getPiliangxinxi(BaseHandler):
    def getEachInfo(self,kw):
        url = "http://open.api.tianyancha.com/services/v4/open/baseinfo"
        numpat = re.compile(u'\d+')
        num_result = numpat.findall(kw)
        return_json=""
        if len(num_result) > 0 and num_result[0] == kw:  # 代表是id
            # print("发送搜索id的请求")
            url += "?id=" + kw
            req = urllib2.Request(url)
            req.add_header("Authorization", conf.Authorization)
            res_data = urllib2.urlopen(req)
            res = res_data.read()
            return_json = json.loads(str(res))
            # json.loads('''{"error_code":0,"reason":"ok","result":{"updatetime":1530084562162,"fromTime":991670400000,"type":1,"categoryScore":9436,"id":22822,"regNumber":"110108002734659","percentileScore":9723,"regCapital":"642128.000000万人民币","regInstitute":"北京市工商行政管理局海淀分局","name":"北京百度网讯科技有限公司","regLocation":"北京市海淀区上地十街10号百度大厦2层","industry":"科技推广和应用服务业","approvedTime":1529856000000,"logo":"http://img.tianyancha.com/logo/lll/36089e162a250252363a05d74b96185b.png@!watermark01","orgApprovedInstitute":"北京市质量技术监督局","taxNumber":"91110000802100433B","businessScope":"技术服务、技术培训、技术推广；设计、开发、销售计算机软件；经济信息咨询；利用www.baidu.com、www.hao123.com(www.hao222.net、www.hao222.com)网站发布广告；设计、制作、代理、发布广告；货物进出口、技术进出口、代理进出口；医疗软件技术开发；委托生产电子产品、玩具、照相器材；销售家用电器、机械设备、五金交电、电子产品、文化用品、照相器材、计算机、软件及辅助设备、化妆品、卫生用品、体育用品、纺织品、服装、鞋帽、日用品、家具、首饰、避孕器具、工艺品、钟表、眼镜、玩具、汽车及摩托车配件、仪器仪表、塑料制品、花、草及观赏植物、建筑材料、通讯设备；预防保健咨询；公园门票、文艺演出、体育赛事、展览会票务代理；翻译服务；因特网信息服务业务（除出版、教育、医疗保健以外的内容）；第一类增值电信业务中的在线数据处理与交易处理业务、国内因特网虚拟专用网业务、因特网数据中心业务；第二类增值电信业务中的因特网接入服务业务、呼叫中心业务、信息服务业务（不含固定网电话信息服务和互联网信息服务）；图书、电子出版物、音像制品批发、零售、网上销售；利用信息网络经营音乐娱乐产品，游戏产品，演出剧（节）目、表演，动漫产品（文化经营许可证有效期至2020年04月17日）；演出经纪；人才中介服务。（企业依法自主选择经营项目，开展经营活动；演出经纪、人才中介服务以及依法须经批准的项目，经相关部门批准后依批准的内容开展经营活动；不得从事本市产业政策禁止和限制类项目的经营活动。）","property4":"110108802100433","property3":"Beijing Baidu Netcom Science and Technology Co.,Ltd.","orgNumber":"802100433","regStatus":"开业","estiblishTime":991670400000,"legalPersonName":"梁志祥","toTime":1622736000000,"legalPersonId":2020172991,"sourceFlag":"http://qyxy.baic.gov.cn/","actualCapital":"","flag":1,"correctCompanyId":"","companyOrgType":"有限责任公司(自然人投资或控股)","base":"bj","updateTimes":1530084554000,"companyType":32767,"creditCode":"91110000802100433B","companyId":431}}''')
        else:  #
            # print("发送搜索name的请求")
            url += "?name=" + kw
            req = urllib2.Request(url)
            req.add_header("Authorization", conf.Authorization)
            res_data = urllib2.urlopen(req)
            res = res_data.read()
            return_json = json.loads(str(res))
        return return_json



    def post(self):
        #保存成文件
        listfile=self.request.files["listfile"][0]
        filename=listfile["filename"]
        houzhui=filename.split(".")[len(filename.split("."))-1]
        uuid=getUuid()
        filename=uuid+"."+houzhui
        #filename=filename.decode("utf-8")

        tmpfile=open("/Users/jingjian/tmp/"+filename,"wr")
        tmpfile.write(listfile["body"])
        tmpfile.flush()
        tmpfile.close()
        #解析excel文件
        excelFile = xlrd.open_workbook("/Users/jingjian/tmp/"+filename)
        sheet=excelFile.sheet_by_index(0)
        #print sheet.name,sheet.nrows,sheet.ncols
        name_list=[]
        for each_row_index in range(sheet.nrows):
            name_each= str(sheet.row_values(each_row_index)[0])
            name_each=name_each.replace(" ","")
            if len(name_each)>0:
                name_list.append(name_each)

        #设置用于导出的excel
        #新建
        outExcelFile=xlwt.Workbook(encoding = 'utf-8')
        sheet = outExcelFile.add_sheet("sheet1")
        sheet.write(0, 0,"公司名")
        sheet.write(0, 1, "英文名")
        sheet.write(0, 2, "注册号")
        sheet.write(0, 3, "注册资金")
        sheet.write(0, 4, "注册时间")
        sheet.write(0, 5, "组织机构代码")
        sheet.write(0, 6, "公司类型")
        sheet.write(0, 7, "省份简称")
        sheet.write(0, 8, "法人代表")
        sheet.write(0, 9, "经营状态")
        sheet.write(0, 10, "行业")
        sheet.write(0, 11, "社会同一信用代码")
        result={}
        index=0
        for each_name in name_list:
            print each_name
            index+=1
            return_sjon=self.getEachInfo(kw=each_name)
            print return_sjon
            #print each_name
            #print return_sjon
            if return_sjon["error_code"]==0:
                each_return_json={}
                each_return_json["boo"]="true"
                each_result=return_sjon["result"]
                # 公司名 name
                name=each_result["name"]
                each_return_json["name"]=name
                sheet.write(index, 0, name)
                # 英文名 property3
                if "property3" in each_result:
                    property3 = each_result["property3"]
                    each_return_json["property3"] = property3
                    sheet.write(index, 1, property3)
                else:
                    each_return_json["property3"] = ""
                    sheet.write(index, 1, "")
                # 注册号 regNumber
                regNumber = each_result["regNumber"]
                each_return_json["regNumber"] = regNumber
                sheet.write(index, 2, regNumber)
                # 注册资金 regCapital
                regCapital = each_result["regCapital"]
                each_return_json["regCapital"] = regCapital
                sheet.write(index, 3, regCapital)
                # 注册时间 estiblishTime
                estiblishTime = each_result["estiblishTime"]
                time_local = time.localtime(estiblishTime/1000)
                dtime=time.strftime("%Y-%m-%d",time_local)
                each_return_json["estiblishTime"] = dtime
                sheet.write(index, 4, dtime)
                # 组织机构代码 orgNumber
                orgNumber = each_result["orgNumber"]
                each_return_json["orgNumber"] = orgNumber
                sheet.write(index, 5, orgNumber)
                # 公司类型 companyOrgType
                companyOrgType = each_result["companyOrgType"]
                each_return_json["companyOrgType"] = companyOrgType
                sheet.write(index, 6, companyOrgType)
                # 省份简称 base
                base = each_result["base"]
                each_return_json["base"] = base
                sheet.write(index, 7, base)
                # 法人代表 legalPersonName
                legalPersonName = each_result["legalPersonName"]
                each_return_json["legalPersonName"] = legalPersonName
                sheet.write(index, 8, legalPersonName)
                # 经营状态 regStatus
                regStatus = each_result["regStatus"]
                each_return_json["regStatus"] = regStatus
                sheet.write(index, 9, regStatus)
                # 行业 industry
                industry = each_result["industry"]
                each_return_json["industry"] = industry
                sheet.write(index, 10, industry)
                # 社会统一信用代码 creditCode
                creditCode = each_result["creditCode"]
                each_return_json["creditCode"] = creditCode
                sheet.write(index, 11, creditCode)
                result[index]=each_return_json
            else:
                each_return_json = {}
                each_return_json["boo"] = "false"
                each_return_json["name"] = each_name
                sheet.write(index, 0, each_name)
                sheet.write(index, 1, "暂无数据")
                result[index] = each_return_json
        result["size"]=index
        result["filename"] = "out"+uuid+".xls"
        outExcelFile.save("/Users/jingjian/tmp/out"+uuid+".xls")



        self.write(result)

    def get(self):
        filename = self.get_argument("filename")
        print('i download file handler : ', filename)
        # Content-Type这里我写的时候是固定的了，也可以根据实际情况传值进来
        self.set_header('Content-Type', 'application/octet-stream')
        self.set_header('Content-Disposition', 'attachment; filename=' + filename)
        # 读取的模式需要根据实际情况进行修改
        with open("/Users/jingjian/tmp/"+filename, 'rb') as f:
            while True:
                data = f.read(100)
                if not data:
                    break
                self.write(data)
        # 记得有finish哦
        self.finish()


class yinhangliushui(BaseHandler):
    #银行流水对账单抽取&审核页面= =
    def get(self):
        self.render("sys/zhongde/yinhangliushui.html")